package com.sunny.myproject.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.sunny.myproject.core.base.service.BaseServiceImpl;
import com.sunny.myproject.system.dao.UserDao;
import com.sunny.myproject.system.entity.User;
import com.sunny.myproject.system.service.UserService;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 *
 * @author sunnynie
 * @email sunnynie89@gmail.com
 */
@Repository
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService{

	@Autowired
	private UserDao dao;
	
	@Override
	public List<User> findAll() {
		List<Criterion> criterions = new ArrayList<Criterion>();
		return dao.getList(criterions);
	}

	@Override
	public User findByName(String name) {
		List<Criterion> criterions = new ArrayList<Criterion>();
		criterions.add(Restrictions.eq("name", name));
		return dao.getList(criterions).get(0);
	}

	@Override
	public User findByLoginName(String loginName) {
		List<Criterion> criterions = new ArrayList<Criterion>();
		criterions.add(Restrictions.eq("loginName", loginName));
		return dao.getList(criterions).get(0);
	}

}
